package src.com.test.oneDay;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class demo1 {
    public static void main(String[] args) {

        demo1 demo1 = new demo1();
        List<List<Integer>> combine = demo1.combine(4, 2);
        System.out.println(combine);
    }

    List<List<Integer>> res = new ArrayList<>();
    LinkedList<Integer> path = new LinkedList<>();

    public List<List<Integer>> combine(int n, int k) {
        traceBacking(n,k,1);
        return res;
    }

    public void traceBacking(int n,int k,int startIndex){
        if(path.size() == k){
            res.add(new ArrayList<>(path));
            return;
        }
        for(int i = startIndex;i <= n;i++){
            path.add(i);
            traceBacking(n,k,i+1);
            path.removeLast();
        }
    }
}
